import { GET, POST } from "@/api";
import { config } from "@/config";
import { VagueOject } from "@/types/common";
import { IndexType,ClassType } from "@/types/res/home";

export const index = async (data: VagueOject = {}, header: VagueOject = {}): Promise<IndexType[]> => {
    let res = await POST<IndexType[]>({
        url: config.apiList.index,
        data,
        header
    })

    res.forEach(v => {
        v.wares_masterimg = JSON.parse(<string>v.wares_masterimg)
    })

    return res;
}


export const info = async (data: VagueOject = {}, header: VagueOject = {}): Promise<IndexType> => {
    let res = await POST<IndexType>({
        url: config.apiList.info,
        data,
        header
    })
    res.wares_masterimg = JSON.parse(<string>res.wares_masterimg)
    res.wares_infoimg = JSON.parse(<string>res.wares_infoimg)
    return res;
}

export const search = async (data: VagueOject = {}, header: VagueOject = {}): Promise<IndexType[]> => {
    let res = await POST<IndexType[]>({
        url: config.apiList.search,
        data,
        header
    })
    res.forEach(e => {
        e.wares_masterimg = JSON.parse(<string>e.wares_masterimg)
        e.wares_infoimg = JSON.parse(<string>e.wares_infoimg)
    });
    
    return res;
}
export const activity = async (data: VagueOject = {}, header: VagueOject = {}): Promise<IndexType[]> => {
    let res = await POST<IndexType[]>({
        url: config.apiList.activity,
        data,
        header
    })
    res.forEach(e => {
        e.wares_masterimg = JSON.parse(<string>e.wares_masterimg)
        e.wares_infoimg = JSON.parse(<string>e.wares_infoimg)
    });
    // console.log(res);
    
    // res.wares_masterimg = JSON.parse(<string>res.wares_masterimg)
    // res.wares_infoimg = JSON.parse(<string>res.wares_infoimg)
    return res;
}

//首页分类
export const likeList = async (data: VagueOject = {}, header: VagueOject = {}): Promise<IndexType[]> => {
    let res = await POST<IndexType[]>({
        url: config.apiList.likeList,
        data,
        header
    })

    res.forEach(e => {
        e.wares_masterimg = JSON.parse(<string>e.wares_masterimg)
        e.wares_infoimg = JSON.parse(<string>e.wares_infoimg)
    });
    // console.log('收藏',res);
    
    // res.wares_masterimg = JSON.parse(<string>res.wares_masterimg)
    // res.wares_infoimg = JSON.parse(<string>res.wares_infoimg)
    return res;
}
//分类页面
export const list = async (data: VagueOject = {}, header: VagueOject = {}): Promise<ClassType[]> => {
    let res = await POST<ClassType[]>({
        url: config.apiList.list,
        data,
        header
    })

    
    // res.wares_masterimg = JSON.parse(<string>res.wares_masterimg)
    // res.wares_infoimg = JSON.parse(<string>res.wares_infoimg)
    return res;
}
